/**
 * Copyright (C) 2013 DaiKit.com - daikit4gxt module (admin@daikit.com)
 *
 *         Project home : http://code.daikit.com/daikit4gxt
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.daikit.daikit4gxt.client.ui.component;

import com.google.gwt.i18n.client.HasDirection.Direction;
import com.google.gwt.i18n.shared.DirectionEstimator;
import com.google.gwt.user.client.ui.InlineLabel;
import com.sencha.gxt.widget.core.client.container.SimpleContainer;


/**
 * A simple inline label Component that can be added in GXT context (unlinke {@link InlineLabel} which is a GWT
 * component (not GXT)
 * 
 * @author tcaselli
 * @version $Revision$ Last modifier: $Author$ Last commit: $Date$
 */
public class DkInlineLabel extends SimpleContainer
{

	private final InlineLabel inlineLabel;

	/**
	 * Constructor
	 */
	public DkInlineLabel()
	{
		inlineLabel = new InlineLabel();
		add(inlineLabel);
	}

	/**
	 * Constructor
	 * 
	 * @param text
	 */
	public DkInlineLabel(final String text)
	{
		this();
		setText(text);
	}

	/**
	 * Constructor
	 * 
	 * @param text
	 * @param dir
	 */
	public DkInlineLabel(final String text, final Direction dir)
	{
		this();
		setText(text, dir);
	}

	/**
	 * Constructor
	 * 
	 * @param text
	 * @param directionEstimator
	 */
	public DkInlineLabel(final String text, final DirectionEstimator directionEstimator)
	{
		this();
		setText(text);
		inlineLabel.setDirectionEstimator(directionEstimator);
	}

	/**
	 * Sets the label's content to the given text.
	 * <p>
	 * Doesn't change the widget's direction or horizontal alignment if {@code directionEstimator} is null. Otherwise,
	 * the widget's direction is set using the estimator, and its alignment may therefore change as described in
	 * {@link #setText(String, com.google.gwt.i18n.client.HasDirection.Direction) setText(String, Direction)}.
	 * 
	 * @param text
	 *           the widget's new text
	 */
	public void setText(final String text)
	{
		inlineLabel.setText(text);
	}

	/**
	 * Sets the label's content to the given text, applying the given direction.
	 * <p>
	 * This will have the following effect on the horizontal alignment:
	 * <ul>
	 * <li>If the automatic alignment setting is ALIGN_CONTENT_START or ALIGN_CONTENT_END, the horizontal alignment will
	 * be set to match the start or end edge, respectively, of the new direction (the {@code dir} parameter). If that is
	 * DEFAULT, the locale direction is used.
	 * <li>Otherwise, the horizontal alignment value is not changed, but the effective alignment may nevertheless change
	 * according to the usual HTML rules, i.e. it will match the start edge of the new direction if the widget element is
	 * a &lt;div&gt; and has no explicit alignment value even by inheritance.
	 * </ul>
	 * 
	 * @param text
	 *           the widget's new text
	 * @param dir
	 *           the text's direction. Note: {@code Direction.DEFAULT} means direction should be inherited from the
	 *           widget's parent element.
	 */
	public void setText(final String text, final Direction dir)
	{
		inlineLabel.setText(text, dir);
	}

	/**
	 * @return the inlineLabel
	 */
	public InlineLabel getInlineLabel()
	{
		return inlineLabel;
	}
}
